<!DOCTYPE html>
<html>
<head>
<title> Calling stopPropagation() prior to dispatchEvent() </title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>

<table id="table" border="1" style="display: none">
    <tbody id="table-body">
    <tr id="table-row">
        <td id="table-cell">Shady Grove</td>
        <td>Aeolian</td>
    </tr>
    <tr id="parent">    
        <td id="target">Over the river, Charlie</td>
        <td>Dorian</td>
    </tr>
    </tbody>
</table>
        
<script>
    var EVENT = "foo";    
    var TARGET = document.getElementById("target");
    var PARENT = document.getElementById("parent"); 
    var TBODY = document.getElementById("table-body");
    var TABLE = document.getElementById("table");
    var BODY = document.body;
    var HTML = document.documentElement;                
    var CurrentTargets = [window, document, HTML, BODY, TABLE, TBODY, PARENT, TARGET];
    var ExpectResult = [];
    var ActualResult = [];
    var ExpectPhases = [];
    var ActualPhases = [];

    var description = "Test Description: " + 
                      "If Event.stopPropagation() has been called prior to the dispatch, all phases must be skipped."; 
    test(function()
    {
        for (var i=0; i < CurrentTargets.length; i++)
        {
            CurrentTargets[i].addEventListener(EVENT, TestEvent, true);
            CurrentTargets[i].addEventListener(EVENT, TestEvent, false);
        }
       
        var evt = document.createEvent("Event");
        evt.initEvent(EVENT, true, true);
        evt.stopPropagation();              
        TARGET.dispatchEvent(evt);

        assert_array_equals(ActualResult, ExpectResult, "ActualResult");
        assert_array_equals(ActualPhases, ExpectPhases, "ActualPhases");
        
    }, description);
         
    function TestEvent(evt)
    {   
        ActualResult.push(evt.currentTarget);         
        ActualPhases.push(evt.eventPhase);                   
    }
</script>
</body>
</html>
